<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-2.2.3.min.js" type="text/javascript"></script>
</head>
<body>
<div>
    <label for="username"></label>
    <input type="text" name="username" id="username">
    <label for="password"></label>
    <input type="password" name="password" id="password">
    <button id="login">登录</button>
</div>
<button id="testClick">点击获取</button>
</body>
<script>

    $("#login").click(function () {
        $.ajax({
            url:"http://127.0.0.1:8080/macro/login",
            type:"POST",
            async: false,
            dataType: "json",
            contentType: "application/json",
            data: JSON.stringify({
                "username": $("#username").val(),
                "password": $("#password").val(),
                "logintype":"operate"
            }),
            success:function (data,status, xhr) {
                console.log(data);
                if (data.code==200){
                    localStorage.setItem("token::macro", xhr.getResponseHeader("Authorization"));
                }else{
                    alert(data.message);
                }
            }
        })
    });


    $("#testClick").click(function () {
        $.ajax( {
            url:"http://127.0.0.1:8080/macro/test",
            type:"GET",
            headers:{
                "Authorization":localStorage.getItem("token::macro")
            },
            success:function (data) {
                console.log(data);
            }
        })
    })
</script>
</html>